function [TotalPayoff Buy Sell] = tradingStrategy1(rPortfolioTest, myVaRup, V0)
    %strategy 1: buy when rPortfolioTest(i) under myVaRdown, sell 4 days after
    
    TotalPayoff = 1;
    Buy_Position = 0; 
    days = 0;
    numOfDays = 4;
    Buy = []; Sell = [];

    for i = 1:length(rPortfolioTest)
        if (rPortfolioTest(i,:) >= myVaRup(i) && Buy_Position == 0)
            Buy_Position = 1;
            Buy = [Buy; rPortfolioTest(i, :)];
            Sell = [Sell; 0];
            lastdaybuy = i;
        elseif (days >= numOfDays - 1)
            TotalPayoff = TotalPayoff .* ((1+rPortfolioTest(lastdaybuy+1,:)).*(1+rPortfolioTest(lastdaybuy+2,:)).*(1+rPortfolioTest(lastdaybuy+3,:)))*(1-0.0003*2);
            days = 0;
            Buy_Position = 0;        
            Buy = [Buy; 0];
            Sell = [Sell; rPortfolioTest(i, :)];
        elseif (Buy_Position == 1)
            days = days + 1;
            Buy = [Buy; 0];
            Sell = [Sell; 0];
        else
            Buy = [Buy; 0];
            Sell = [Sell; 0];
        end
    end
    
    lastReturn = 1;
    if((length(rPortfolioTest)-lastdaybuy) < 4 && Buy_Position == 1)
        for i=1:(length(rPortfolioTest)-lastdaybuy-1)
            lastReturn = lastReturn*(1+rPortfolioTest(end-i,:))*(1-0.0003*2);
        end
        
        TotalPayoff = TotalPayoff .* lastReturn;
    end
    
    TotalPayoff = TotalPayoff - 1;